<template>
    <div id="monthWork">
       <el-row>
         <el-col :span="6"><div class="grid-content"></div></el-col>
         <el-col :span="10">
           <div class="grid-content">
             <el-form :label-position="labelPosition" :rules="rules" ref="form" :model="form" label-width="80px">
              <el-form-item label="选择日期" prop="weekly_date">
                <el-col :span="24">
                  <el-date-picker type="date" value-format="yyyy-MM-dd" placeholder="选择日期" v-model="form.weekly_date" style="width: 100%;"></el-date-picker>
                </el-col>
              </el-form-item>
              <el-form-item label="项目组" prop="group">
                <el-col :span="24">
                  <el-select style="width: 100%;" v-model="form.group" clearable placeholder="请选择项目组">
                    <el-option
                      v-for="item in groupOptions"
                      :key="item.value"
                      :label="item.label"
                      :value="item.value">
                    </el-option>
                  </el-select>
                </el-col>
              </el-form-item>
              <el-form-item label="上周总结" prop="summary_of_last_week">
                <el-col :span="24">
                  <el-input type="textarea" :rows="5" v-model="form.summary_of_last_week"></el-input>
                </el-col>
              </el-form-item>
              <el-form-item label="本周计划" prop="this_week_plan">
                <el-col :span="24">
                  <el-input type="textarea" :rows="5" v-model="form.this_week_plan"></el-input>
                </el-col>
              </el-form-item>
              <el-form-item>
                <el-button type="primary" @click="onSubmit('form')">提交</el-button>
                <el-button @click="resetForm('form')">重置</el-button>
              </el-form-item>
            </el-form>
           </div>
           </el-col>
         <el-col :span="8"><div class="grid-content"></div></el-col>
       </el-row>
    </div>
</template>
<script>
export default {
  name: 'monthWork',
  data () {
    return {
      form: {
          weekly_date: '',
          group:'',
          summary_of_last_week: '',
          this_week_plan: ''
        },
        rules: {
          weekly_date: [
            { required: true, message: '请选择日期', trigger: 'change' }
          ],
          group: [
            { required: true, message: '请选择项目组', trigger: 'change' }
          ],
          summary_of_last_week: [
            { required: true, message: '请输入上周总结', trigger: 'blur' }
          ],
          this_week_plan: [
            { required: true, message: '请输入本周计划', trigger: 'blur' }
          ]
        },
        labelPosition: 'right',
        groupOptions:[]
    }
  },
  created() {
    this.getGroupList();
  },
  beforeDestroy() {},
  computed: {},
  mounted() {},
  methods: {
    onSubmit(formName) {
      console.log('submit!');
      this.$refs[formName].validate((valid) => {
          if (valid) {
            var self = this;
            self.postRequest("/weekly/addWeekly", {
              group_id:self.form.group,
              weekly_date:self.form.weekly_date,
              summary_of_last_week:self.form.summary_of_last_week,
              this_week_plan:self.form.this_week_plan
            }).then(
              res => {      
                console.log(res)     
                if(res.data.result == '1' ){            
                  this.$message({
                      message: res.data.message,
                      type: 'success'
                  });
                  console.log(res)
                  self.$router.push('/weekWorkList');
                }else if(res.data.result == '2' ){
                  this.$message({
                      message: res.data.message,
                      type: 'error'
                  });
                }
              }
            ); 
          }
      })
    },
    resetForm(formName) {
      this.$refs[formName].resetFields();
    },
    getGroupList() {
      var self = this;
      //console.log(self.currentPage)
      self.getRequest("/base/common/queryProjectName?flug="+1, {}).then(
        res => {      
          console.log(res.resultData)     
          var obj = res.data.resultData;
            var arr = [];
            for(var i in obj) {
              var row = {};
              row.label = obj[i].pName;
              row.value = obj[i].id;
              arr.push(row);
            }
            //console.log(arr)
            self.groupOptions = arr;
        }
      );
    }
  }
}
</script>

<style scoped>
  .grid-content {
    min-height: 36px;
  }
</style>